package com.usian.wemedia.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.impl.WmUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/user")
public class WmUserController implements WmUserControllerApi {

    @Autowired
   private WmUserServiceImpl wmUserService;

    @RequestMapping("save")
    @Override
    public ResponseResult save(@RequestBody WmUser dto) {
        if (dto==null)return wmUserService.errorParam;
        wmUserService.save(dto);
        return ResponseResult.okResult(dto);
    }

    @GetMapping("/findByName/{name}")
    @Override
    public WmUser findByName(@PathVariable("name") String name) {
       return wmUserService.getOne(Wrappers.<WmUser>lambdaQuery().eq(StringUtils.isNotEmpty(name), WmUser::getName, name));
    }

    @PostMapping("/updateAuthorId")
    @Override
    public ResponseResult updateAuthorId(@RequestBody WmUser wmUser) {
        if (wmUser==null||wmUser.getId()==null)return wmUserService.errorParam;
        wmUserService.updateById(wmUser);
        return wmUserService.success;
    }


}
